<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .right button{
            border-radius: 50%;
            font-size: 20px;
        }
        .title {
            display: flex;
            justify-content: space-around;
        }
        .title .title1{
            font-size: 26px;
        }
        .list .item{
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin: 20px;
        }
        img{
            width: 60px;
        }
        .bottom{
            display: flex;
            justify-content: space-around;
            background-color: brown;
            margin-top: 150px;
        }
        .bottom button{
            
            font-size: 26px;
            background-color: aqua;
            margin: 20px;
        }
        .bottom .zongshu{
            font-size: 26px;
            margin: 20px;
            background-color: aquamarine;
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="title">
            <div class="title1">已选商品</div>
            <div class="title2" @click="del(item)">删除</div>
        </div>
        <div class="list">
            <div class="item" v-for="(item,index) in tasklist" v-bind:key="index">
                <div class="left">
                    <img v-bind:src="item.pic" alt="">
                </div>
                <div class="middle">
                    <div class="name">{{item.name}}</div>
                    <div class="price">{{item.price}}</div>
                </div>
                <div class="right">
                    <button class="jian" @click="jian1(item)"> - </button>
                    <span>{{item.num}}</span>
                    <button class="jia" @click="jia1(item)"> + </button>
                </div>
            </div>
        </div>
        <div class="bottom">
            <div class="zongshu">总价<span v-text="numa()"></span>元</div>
            <button >总数<span v-text="numb()"></span>个</button>
        </div>
    </div>
</body>
<script src="./vue-2.5.21.js"></script>
<script>
    var v=new Vue({
        el:'#app',
        data:{
            tasklist:[
                {id:1,pic:'./ing/04.webp',name:'秋刀鱼/斤',price:'35.00',num:1},
                {id:2,pic:'./ing/05.webp',name:'鲜大带鱼/条',price:'45.00',num:2},
                {id:3,pic:'./ing/06.webp',name:'鲜活全母皮皮虾/斤',price:'85.00',num:3},
            ]
        },
        methods:{
            jian1(item){
                item.num--
                if(item.num<1){
                    item.num=1
                    alert('至少购买一条')
                }
            },
            jia1(item){
                item.num++
                if(item.num>5){
                    item.num=5
                    alert('最多购买五条')
                }
            },
            del(item){
                this.tasklist=[]
            },
            numa(){
                var numa=0
                this.tasklist.forEach((item,index)=>{
                    numa+=item.price*item.num
                })
                return numa
            },
            numb(){
                var numa=0
                this.tasklist.forEach((item,index)=>{
                    numa+=item.num
                })
                return numa
            }
        }
        
    })
</script>
</html>